@extends('cms/system/admin/template/theme_default/common')
@section('page-body')
    <div class="layui-form" id="system-menu-form" lay-filter="system-menu-form" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">所属站点</label>
            <div class="layui-input-block">
                <input id="site-id" type="hidden" name="site_id" value="{{$data['site_id'] ?? $site['id']}}" />
                <input id="site-select" class="layui-input" type="text" value="{{$site['name']}}" placeholder="请选择所属站点" autocomplete="off" lay-verify="required" required readonly />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">题库名称</label>
            <div class="layui-input-block">
                <input class="layui-input" type="text" name="name" value="{{$data['name'] ?? ''}}" placeholder="请输入题库名称" autocomplete="off" lay-verify="required" required />
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="button" value="添加" id="submit-create" lay-submit lay-filter="submit-create" />
            <input type="button" value="更新" id="submit-update" lay-submit lay-filter="submit-update" />
        </div>
    </div>
    <script type="text/javascript">
        layui.config({
            base: '/layui-admin/'
        }).extend({
            index: 'lib/index'
        }).use(['index'], function () {
            // 创建
            layui.form.on('submit(submit-create)', function (data) {
                // 获取提交的字段
                var formField = data.field;
                // 当前iframe层的索引
                var layerIndex = parent.layer.getFrameIndex(window.name);
                // ajax提交
                layui.$.ajax({
                    url: layui.setter.apiLink + '/exam/admin_topic_group/create?site_id={{$site['id'] ?? 0}}',
                    type: 'POST',
                    data: formField,
                    success: function (result) {
                        // 重载表格
                        parent.layui.table.reload('system-menu-list');
                        // 关闭弹层
                        parent.layer.close(layerIndex);
                    }
                });
            });
            // 更新
            layui.form.on('submit(submit-update)', function (data) {
                // 获取提交的字段
                var formField = data.field;
                // 当前iframe层的索引
                var layerIndex = parent.layer.getFrameIndex(window.name);
                // ajax提交
                layui.$.ajax({
                    url: layui.setter.apiLink + '/exam/admin_topic_group/update?id={{$data['id'] ?? 0}}',
                    type: 'POST',
                    data: formField,
                    success: function (result) {
                        // 重载表格
                        parent.layui.table.reload('system-menu-list');
                        // 关闭弹层
                        parent.layer.close(layerIndex);
                    }
                });
            });
        });
    </script>
@endsection